package api;

import utils.CommUtils;
import utils.HttpUtils;

import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;

/**
 * 身份证核验API接口
 */
public class IdApi extends AccessToken {
    private final static String idElem2URI = "/aip/check/v1/id/elem2";
    private final static String idElem3URI = "/aip/check/v1/id/elem3";

    /**
     * 1.身份证二要素核验
     */
    public static void idElem2(String _BizNo, String cardName, String cardCode) {
        Map<String, Object> paramsMap = new TreeMap<>();
        paramsMap.put("appId", appId);
        paramsMap.put("cardName", cardName);
        paramsMap.put("cardCode", cardCode);
        paramsMap.put("_BizNo", _BizNo);
        paramsMap.put("sign", CommUtils.sign(paramsMap, secretKey));
        String res = HttpUtils.doPostJSON(host, idElem2URI, getCachedAccessToken(), paramsMap);
        System.out.println("身份证二要素核验-- >> idElem2:" + res);
    }

    /**
     * 2.身份证三要素核验
     */
    public static void idElem3(String _BizNo, String cardName, String cardCode, String faceImage) {
        Map<String, Object> paramsMap = new TreeMap<>();
        paramsMap.put("appId", appId);
        paramsMap.put("cardName", cardName);
        paramsMap.put("cardCode", cardCode);
        paramsMap.put("faceImage", faceImage);
        paramsMap.put("_BizNo", _BizNo);
        paramsMap.put("sign", CommUtils.sign(paramsMap, secretKey));
        String res = HttpUtils.doPostJSON(host, idElem3URI, getCachedAccessToken(), paramsMap);
        System.out.println("身份证三要素核验-- >> idElem3:" + res);
    }


    public static void main(String[] args) {
        String image = CommUtils.fileToBase64Str("H:\\Download\\8db04e8c49682a4ca87d51c24d296972_351102010067517441.jpg");
        //1.身份证二要素核验
        idElem2(UUID.randomUUID().toString(), "张三", "440804188006070125");
        //2.身份证三要素核验
        idElem3(UUID.randomUUID().toString(), "张三", "440804188006070125", image);
    }

}
